
var defaultLocation = {
	latitude: 37.4443,
	longitude: -122.1422
};

var map = null;
var mapMarker = null;
var mapParams = {};

var initGoogleMapWithMarker = function(mode, options, callback) {
	
	var defaults = {
		position : defaultLocation,
		mode   : mode,
		target : 'map',
		zoom   : 10,
		mapTypeId : google.maps.MapTypeId.ROADMAP,
		draggable : true
	};
	
	mapParams = $.extend({}, defaults, options);
	
	var location = new google.maps.LatLng( mapParams.position.latitude, mapParams.position.longitude );

	var mapOptions = {
		zoom: mapParams.zoom,
		center: location,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	map = new google.maps.Map(document.getElementById( mapParams.target ), mapOptions);

	mapMarker = new google.maps.Marker({
		position: location, 
		map: map,
		draggable: mapParams.draggable
	});
   
	google.maps.event.addListener(mapMarker, 'dragend', function(event) {
		callback(event, map, mapMarker);
	});
	
	return map;
};

var adjustGoogleMap = function(options) {
	mapParams = $.extend({}, mapParams, options);
	var location = new google.maps.LatLng( mapParams.position.latitude, mapParams.position.longitude );
	map.setCenter( location );
	mapMarker.setPosition( location );
};